package com.xiaoyu.fish.service.impl;

import com.xiaoyu.fish.dto.LocationDto;
import com.xiaoyu.fish.mapper.LocationMapper;
import com.xiaoyu.fish.pojo.Callout;
import com.xiaoyu.fish.pojo.Location;
import com.xiaoyu.fish.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class LocationServiceImpl implements LocationService {

    @Autowired
    private LocationMapper locationMapper;

    @Override
    public String savePosition(LocationDto locationDto) {
        locationMapper.savePosition(locationDto);
        return "保存地点成功！";
    }

    @Override
    public String deleteLocation(Integer id) {
        locationMapper.deleteLocation(id);
        return "删除成功！";
    }

    @Override
    public Location selectPointOne(Integer id) {
        Location location = locationMapper.selectPointOne(id);
        Callout callout = new Callout();
        callout.setContent(location.getName());
        location.setCallout(callout);
        return location;
    }


    @Override
    public String renameLocation(LocationDto locationDto) {
        locationMapper.renameLocation(locationDto);
        return "修改成功！";
    }

    @Override
    public List<Location> listPoint() {
        List<Location> locationResult = locationMapper.listPoint();
        for (Location location : locationResult) {
            Callout callout = new Callout();
            callout.setContent(location.getName());
            location.setCallout(callout);
        }
        return locationResult;
    }

}
